<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>东单办公系统-部门列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="media/layui/css/layui.css" media="all">
    <script src="media/js/jquery.min.js"></script>
</head>
<body>
<div class="layui-container">
    <table id="tbdata" lay-filter="tbop"></table>
    <script type="text/html" id="barop">
        <a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
    </script>
</div>
<script src="media/layui/layui.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use('table', function(){
        var table = layui.table;
        //id,name,createtime,flag,week,type
        //第一个实例
        table.render({
            elem: '#tbdata'
            ,url: 'course/coursepage.do' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {type:'checkbox'},
                {field: 'id', title: '序号', sort: true, fixed: 'left'}
                ,{field: 'name', title: '课程名称'}
                ,{field: 'createtime', title: '成立日期'}
                ,{field: 'week', title: '周期'}

                ,{field:'right', title: '操作',toolbar:"#barop"}
            ]]
        });
        //监听工具条
        table.on('tool(tbop)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('是否确认删除部门?', function(index){
                    $.ajax({
                        url: "course/coursedelete.do",
                        type: "POST",
                        data:"id="+data.id,
                        success: function(data){
                            if(data.code==1000){
                                obj.del();//删除表格中的对应行数据
                                layer.close(index);
                                layer.msg("删除成功", {icon: 6});
                            }else{
                                layer.msg("删除失败", {icon: 5});
                            }
                        }
                    });
                });
            } else if(obj.event === 'edit'){//编辑 修改
                location.href="courseupdate.html?d="+ encodeURI(JSON.stringify(data));
            }
        });
    });

</script>
</body>
</html>